package com.xxx.base.rest;

import com.xxx.base.rest.request.TestRequest;
import com.xxx.base.rest.response.RestRet;
import com.xxx.base.service.TestService;
import com.xxx.base.util.Log;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.atomic.AtomicLong;

/**
 * controller invoke DTOGenerator and service.
 * @author xnat
 */
@RestController
@RequestMapping("rest")
public class TestRest {
    protected final Log log = Log.of(getClass());

    @Resource
    private TestService   testService;
//    @Resource
//    TestDao         testDao;
    @Resource
    JpaProperties jpaProperties;



    @GetMapping("json")
    Object json(@RequestBody(required = false) TestRequest pRequest) {
        return RestRet.ok("aaaaaaa");
    }

//    @PostMapping("insert")
//    void insert() {
//        Test test = new Test();
//        test.setLove("afa");
//        test.setName("test");
//        testDao.save(test);
//    }

    @GetMapping("monitor")
    public String monitor() {
        testService.monitor(null);
        return "success";
    }


    AtomicLong userId = new AtomicLong(1);
    @GetMapping("cache")
    public String cache() {
        testService.cache(userId.getAndIncrement(), "couponId");
        return "success";
    }

}
